<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CrateShopLogTable extends Migration
{
    public function up()
    {
        // cash日志 余额
        Schema::create('shop_cash_log', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->string('out_trade_no', 23)->comment('订单号');
            $table->string('operator', 50)->comment('操作人');
            $table->decimal('value', 10, 2)->comment('涉及积分');
            $table->decimal('before', 10, 2)->comment('之前积分');
            $table->decimal('after', 10, 2)->comment('之后积分');
            $table->unsignedTinyInteger('type')->default(0)->comment('操作类型 100=>管理员操作  ,1-10=系统操作 , 11-20 = 消费 ,21-30 = 奖励 , 41-50 =转账操作 ');
            $table->timestamp('created_at')->comment('创建时间');
        });
        // point日志 积分
        Schema::create('shop_sp_log', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->string('out_trade_no', 23)->comment('订单号');
            $table->string('operator', 50)->comment('操作人');
            $table->decimal('value', 10, 2)->comment('涉及积分');
            $table->decimal('before', 10, 2)->comment('之前积分');
            $table->decimal('after', 10, 2)->comment('之后积分');
            $table->unsignedTinyInteger('type')->default(0)->comment('操作类型 100=>管理员操作  ,1-10=系统操作 , 11-20 = 消费 ,21-30 = 奖励 , 41-50 =转账操作 ');
            $table->timestamp('created_at')->comment('创建时间');
        });
        // coupon日志 优惠券
        Schema::create('shop_coupon_log', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->string('out_trade_no', 23)->comment('订单号');
            $table->string('operator', 50)->comment('操作人');
            $table->string('coupon_id', 10)->comment('优惠券ID');
            $table->decimal('value', 10, 2)->comment('面值');
            $table->unsignedTinyInteger('type')->default(0)->comment('操作类型 100=>管理员操作  ,1-10=系统操作 , 11-20 = 消费 ,21-30 = 奖励 , 41-50 =转账操作 ');
            $table->timestamp('created_at')->comment('创建时间');
        });
        //支付表
//        Schema::create('shop_pay_log', function (Blueprint $table) {
//            $table->bigIncrements('id');
//            $table->unsignedInteger('user_id')->nullable()->comment('用户ID');
//            $table->tinyInteger('pay_type')->comment('支付类型  1=余额 ,2=微信, 3=支付宝, 9=线下支付');
//            $table->string('seller_id', 32)->nullable()->comment('商户ID');
//            $table->string('seller_email')->nullable()->comment('商户ID');
//            $table->string('app_id', 32)->nullable()->comment('应用ID');
//            $table->string('subject')->nullable()->comment('商品名称');
//            $table->string('out_trade_no', 23)->comment('商户交易号');
//            $table->string('trade_no', 64)->comment('交易流水号');
//            $table->unsignedDecimal('total_amount', 10, 2)->comment('交易金额');
//            $table->timestamps();
//        });
	    //支付宝异步日志
	    Schema::create('shop_alipay_log', function (Blueprint $table) {
		    $table->bigIncrements('id');
		    $table->string('seller_id', 32)->nullable()->comment('商户ID');
		    $table->string('seller_email')->nullable()->comment('商户ID');
		    $table->string('app_id', 32)->nullable()->comment('应用ID');
		    $table->string('subject')->nullable()->comment('商品名称');
		    $table->string('out_trade_no', 23)->comment('商户交易号');
		    $table->string('trade_no', 64)->comment('交易流水号');
		    $table->string('buyer_id', 32)->comment('买家ID');
		    $table->string('buyer_logon_id')->comment('买家账号');
		    $table->unsignedDecimal('total_amount', 10, 2)->comment('交易金额');
		    $table->timestamps();
	    });
    }

    public function down()
    {
        Schema::dropIfExists('shop_cash_log');
        Schema::dropIfExists('shop_point_log');
        Schema::dropIfExists('shop_coupon_log');
//        Schema::dropIfExists('shop_pay_log');
        Schema::dropIfExists('shop_alipay_log');
    }
}
